package com.fs.system.college_admin.controller;

import com.fs.system.college_admin.service.NoticeService;
import com.fs.system.common.ResponseData;
import com.fs.system.college_admin.domain.Notice;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collegeAdminNotice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @PostMapping("/addNotice")
    public ResponseData addNotice(@RequestBody Notice notice) {
        noticeService.addNotice(notice);
        return new ResponseData("200", "添加成功");
    }

    @GetMapping("/selectNoticeList")
    public ResponseData selectNoticeList(Notice notice) {
        List<Notice> noticeList = noticeService.selectNoticeList(notice);
        return new ResponseData("200", "查询成功",noticeList);
    }

    @GetMapping("/selectPage")
    public ResponseData selectPage(
            Notice notice,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        PageInfo<Notice> noticePageInfo = noticeService.selectPage(notice,pageNum, pageSize);
        return new ResponseData("200", "查询成功",noticePageInfo);
    }

    @PutMapping("/updateNotice")
    public ResponseData updateNotice(@RequestBody Notice notice) {
        noticeService.updateNotice(notice);
        return new ResponseData("200", "修改成功");
    }

    /**
     * 逻辑删除
     */
    @PutMapping("/deleteNotice/{noticeId}")
    public ResponseData deleteNotice(@PathVariable Long noticeId, @RequestParam String updateBy) {
        noticeService.deleteNotice(noticeId, updateBy);
        return new ResponseData("200", "删除成功");
    }

    /**
     * 批量删除
     * @param
     * @return
     */
    @PutMapping("/deleteNoticeBatch/{updateBy}")
    public ResponseData deleteBatch(
            @PathVariable String updateBy,
            @RequestBody List<Long> ids
    ){
        System.out.println(ids);
        noticeService.deleteBatch(ids,updateBy);
        return new ResponseData("200", "批量删除成功");
    }
}
